﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CaiBaby.Common;
using CaiBaby.Entity;

namespace CaiBaby.DAL
{
    /// <summary>
    /// 财宝消费记录数据访问层
    /// </summary>
    public class TreasureLog
    {
        /// <summary>
        /// 增加财宝消费记录
        /// </summary>
        /// <param name="treasureLog">财宝消费记录实体</param>
        /// <returns>返回财宝消费记录ID</returns>
        public int Add(TreasureLogInfo treasureLog)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("INSERT INTO ac_TreasureLog(");
            strSql.Append("UId,Direction,Number,Time,Note)");
            strSql.Append(" VALUES (");
            strSql.Append("@UId,@Direction,@Number,@Time,@Note)");
            strSql.Append(";SELECT @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@UId", SqlDbType.Int,4),
					new SqlParameter("@Direction", SqlDbType.Int,4),
					new SqlParameter("@Number", SqlDbType.Int,4),
					new SqlParameter("@Time", SqlDbType.DateTime),
					new SqlParameter("@Note", SqlDbType.VarChar,512)};
            parameters[0].Value = treasureLog.UId;
            parameters[1].Value = treasureLog.Direction;
            parameters[2].Value = treasureLog.Number;
            parameters[3].Value = treasureLog.Time;
            parameters[4].Value = treasureLog.Note;

            object obj = SQLHelper.GetSingle(ConfigHelper.CaiBabyDBConnStr,CommandType.Text,strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
    }
}
